/* common */
(function () {
    var a = new CookieHelper("player"),
        b, c;
    context.integratedAdMediaPlayer ? (config.urls.playerSwf.indexOf("?") > -1 ? config.urls.playerSwf += "&useAsAdPlayer=1" : config.urls.playerSwf += "?useAsAdPlayer=1", b = null) : b = embedSWF(config.urls.sugrSwf, "sugrSwf", null, {
        callback: "Myspace.Sugr"
    }), c = embedSWF(queryString.swfpath || config.urls.playerSwf, "playerSwf", $("#videoPlayer > div").get(0), {
        callback: "Myspace.Player"
    }), Myspace.Player = {
        resume: function () {
            c.resumeCurrentTrack()
        },
        pause: function () {
            c.pauseCurrentTrack()
        },
        mute: function (b) {
            return b == undefined && (b = !a("mute")), a({
                mute: b
            }), b ? c.setCurrentVolume(0) : c.setCurrentVolume(a("volume")), b
        },
        volume: function (b) {
            return b > 1 && (b = 1), a({
                volume: b,
                mute: !1
            }), c.setCurrentVolume(b), b
        },
        seek: function (a) {
            c.setCurrentPlayTime(a)
        },
        load: function (b, d) {
            if (!b) return;
            d = d || 0, b.mediaType == "video" ? c.loadVideo(b.streamUrl, d, a("paused")) : c.loadSong({
                rtmpURL: b.streamUrl,
                preseek: d,
                autoPause: a("paused")
            })
        },
        loadAd: function (a, b, d) {
            context.integratedAdMediaPlayer ? c.loadAd(a, b, d) : c.loadAd(a, b)
        },
        startAd: function () {
            c.startAd()
        },
        stopAd: function () {
            c.stopAd()
        },
        skipAd: function () {
            c.skipAd()
        },
        pauseAd: function () {
            a({
                paused: !0
            }), c.pauseAd()
        },
        resumeAd: function () {
            a({
                paused: !1
            }), c.resumeAd()
        },
        sendAdClickTracking: function () {
            c.sendAdClickTracking()
        },
        swf: c
    }, context.integratedAdMediaPlayer ? Myspace.Sugr = Myspace.Player : Myspace.Sugr = {
        volume: function (a) {
            b.setVolume(a)
        },
        mute: function (c) {
            c == undefined && (c = !0), c ? b.setVolume(0) : b.setVolume(a("volume"))
        },
        loadAd: function (a, c) {
            b.loadAd(a, c)
        },
        startAd: function () {
            b.startAd()
        },
        stopAd: function () {
            b.stopAd()
        },
        skipAd: function () {
            b.skipAd()
        },
        pauseAd: function () {
            a({
                paused: !0
            }), b.pauseAd()
        },
        resumeAd: function () {
            a({
                paused: !1
            }), b.resumeAd()
        },
        sendAdClickTracking: function () {
            b.sendAdClickTracking()
        },
        swf: b
    }
})();
(function (a, b) {
    "use strict";
    var c = function () {
        this.$container = a("#videoPlayer"), this.width = 310, this.height = 170, this.previewWidth = 207, this.previewHeight = 113, this.wire(), this.setVPos(), this.hide(), this.loading = !1, this.closed = !1, this.alwaysHidden = !1, this.trackingCategory = "videoplayer", this.timeout, this.dialogOpen = !1, this.isPreview = !1
    };
    c.prototype.wire = function () {
        var c = this;
        this.$container.on("click", function (d) {
            var e = a(d.target).closest("[data-action]"),
                f = e.data("action");
            switch (f) {
                case "close":
                    c.hide(), c.closed = !0, c.track(c.trackingCategory, "Hide", context.pfc);
                    break;
                case "expand":
                    comm.send("player.nowPlaying", function (d) {
                        d.mediaItem && d.mediaItem.mediaType === "video" && (c.isVideoDetail() ? c.$container.animate({
                            opacity: .001
                        }, 200, function () {
                            a("body").addClass("fullwindow"), c.$container.animate({
                                opacity: 1
                            }, 200)
                        }) : comm.send("videoLightbox.instance", function (a) {
                            c.hide(), c.track(c.trackingCategory, "Expand", context.pfc), a ? a.show(d.mediaItem, {
                                continuePlay: !0
                            }) : (b.videoReferrer = window.location.pathname, comm.send("location.href", d.mediaItem.detailUrl))
                        }))
                    });
                    break;
                default:
            }
        })
    }, c.prototype.setVPos = function (b) {
        var c = 15;
        b || a("body").hasClass("queueOpen") || a("#drawer").hasClass("message open") ? c += a("#drawer").outerHeight() : c += a("#global").outerHeight(!0) + a("#links").outerHeight(!0), this.$container.css("bottom", c), this.movePageElements({
            bottom: c
        })
    }, c.prototype.setSize = function (a, b) {
        var c = a || this.isPreview ? this.previewWidth : this.width,
            d = b || this.isPreview ? this.previewHeight : this.height;
        this.$container.width(c).height(d)
    }, c.prototype.movePageElements = function (b) {
        var c = b.bottom !== "" ? parseInt(b.bottom) + parseInt(this.$container.height()) + 20 : "";
        a("#popups").css("bottom", c)
    }, c.prototype.show = function () {
        var a = this;
        this.setSize(), this.setVPos(), this.visible = !0, this.closed = !1, this.timeout && clearTimeout(this.timeout), this.timeout = setTimeout(function () {
            a.$container.addClass("open")
        }, 500)
    }, c.prototype.handleShow = function () {
        var a = this;
        comm.send("player.nowPlaying", function (b) {
            a.canShow(b) ? (a.isPreview = b.mediaItem.mediaType == "audio", a.show(), a.track(a.trackingCategory, "Show", context.pfc)) : a.hide()
        })
    }, c.prototype.handleShowAd = function () {
        var a = this,
            b = {
                paused: !1,
                mediaItem: {
                    mediaType: "video",
                    type: "video"
                }
            };
        a.canShow(b) ? (a.isPreview = !1, a.show()) : a.hide()
    }, c.prototype.canShow = function (a) {
        return !this.isVideoDetail() && !this.isLightbox() && !this.alwaysHidden && !this.closed && !this.dialogOpen && typeof a.mediaItem != "undefined" && !a.paused && (a.mediaItem.mediaType == "video" || a.mediaItem.videoId) && (this.isActive() || a.mediaItem.mediaType == "audio")
    }, c.prototype.hide = function () {
        this.visible = !1, this.$container.removeClass("open"), this.movePageElements({
            bottom: ""
        }), this.timeout && clearTimeout(this.timeout)
    }, c.prototype.isVideoDetail = function () {
        return typeof context != "undefined" && context.pfc === "videodetail"
    }, c.prototype.isLightbox = function () {
        var a = !1;
        return comm.send("videoLightbox.instance", function (b) {
            a = Boolean(b && b.isOpen)
        }), a
    }, c.prototype.showLoading = function () {
        this.loading = !0, this.$container.find("#playerSwf").css("opacity", ".01"), this.$container.find(".loading").show()
    }, c.prototype.hideLoading = function () {
        this.loading = !1, this.$container.find(".loading").hide(), this.$container.find("#playerSwf").css("opacity", "1")
    }, c.prototype.drawerToggled = function (a) {
        this.visible && !this.isVideoDetail() && this.setVPos(a)
    }, c.prototype.isActive = function () {
        try {
            return localStorage.activePlayer == scomm.hash
        } catch (a) {}
        return !0
    }, c.prototype.addPlayButton = function (a) {
        var b = this.$container.children("div");
        b.find(".playBtn").remove(), b.append(play("video", a))
    }, c.prototype.track = function (a, b, c) {
        comm.send("track", new Tracking(a, b, c))
    }, c.prototype.showPreview = function (a) {
        a.mediaType == "video" && (this.addPlayButton(a), this.$container.find("> div").css("background-image", "url(" + a.imageUrl + ")"), this.$container.find(".playBtn").click(function () {
            return comm.send("queue.find.video", a), !1
        }), this.hideLoading(), this.handleShow(), this.setSize(this.previewWidth, this.previewHeight), this.$container.addClass("preview")), this.$container.find("#playerSwf").css("opacity", ".01")
    }, c.prototype.removePreview = function () {
        this.$container.hasClass("preview") && (this.$container.find("> div").css("background-image", ""), this.$container.find("#playerSwf").css("opacity", "1"), this.$container.removeClass("preview"))
    }, b.VideoPlayer = new c, comm.listen("drawer.opened", function () {
        b.VideoPlayer.drawerToggled(!0)
    }, !0), comm.listen("drawer.closed", function () {
        b.VideoPlayer.drawerToggled(!1)
    }, !0), comm.listen("player.ended", function (a) {
        a.mediaItem.mediaType == "video" && !b.VideoPlayer.isVideoDetail() && (comm.send("videoLightbox.hide", !0), b.VideoPlayer.hide())
    }, !0), comm.listen("player.loaded", function (a) {
        a.mediaItem.mediaType == "video" && (b.VideoPlayer.hideLoading(), a.paused || b.VideoPlayer.handleShow())
    }, !0), comm.listen("player.resumed", function (a) {
        (a.mediaItem.mediaType == "video" || a.mediaItem.videoId) && b.VideoPlayer.handleShow()
    }, !0), comm.listen("player.loading", function (a) {
        a.mediaItem.mediaType == "video" ? (!b.VideoPlayer.isVideoDetail() && !b.VideoPlayer.isLightbox() && b.VideoPlayer.setSize(), b.VideoPlayer.removePreview(), b.VideoPlayer.showLoading(), b.VideoPlayer.addPlayButton(a.mediaItem)) : !b.VideoPlayer.isVideoDetail() && !a.mediaItem.videoId && b.VideoPlayer.hide()
    }, !0), c.prototype.log = function () {
        console.log.apply(console, arguments)
    }, comm.listen("player.adLoading", function (a) {
        a.isVideo && (b.VideoPlayer.handleShowAd(), b.VideoPlayer.$container.addClass("ad"), b.VideoPlayer.showLoading())
    }, !0), comm.listen("player.adStarted", function (a) {
        a.isVideo && b.VideoPlayer.hideLoading()
    }, !0), comm.listen("player.adStopped", function (a) {
        a.isVideo && (b.VideoPlayer.$container.removeClass("ad"), b.VideoPlayer.hideLoading())
    }, !0), comm.listen("player.onClick", function (a) {
        b.VideoPlayer.log("videoPlayer: player onClick, mediaType: " + a.mediaInfo.mediaType + ", isAd: " + a.mediaInfo.isAd)
    }, !0), comm.listen("spaceway.page.complete", function () {
        b.VideoPlayer.handleShow()
    }, !0), comm.listen("player.queueChanged", function (c) {
        (c == "queue" || c == "preview") && !a("#queue .list." + c + " li").length && (b.VideoPlayer.isVideoDetail() ? comm.send("location.href", b.videoReferrer || "/discover/videos") : (comm.send("videoLightbox.hide"), b.VideoPlayer.hide()))
    }, !0), comm.listen("dialog.showing", function (a) {
        b.VideoPlayer.dialogOpen = !0, b.VideoPlayer.hide()
    }, !0), comm.listen("dialog.hiding", function (a) {
        b.VideoPlayer.dialogOpen = !1, b.VideoPlayer.handleShow()
    }, !0), comm.listen("player.videoPreview", function (a) {
        b.VideoPlayer.showPreview(a)
    }, !0)
})(jQuery, window.Myspace = window.Myspace || {});
(function (a, b) {
    "use strict";
    var c, d = function (e) {
            if (c) return c;
            if (!(this instanceof d)) return new d;
            this.player = e || b.VideoPlayer, this.isOpen = !1, this.uiVisible = !1, this.uiDelay = 2e3, this.rrZindex = 6, this.timeout = null, this.coverClass, this.playerClass, this.updateLocation, this.showRightRail, this.$expand = this.player.$container.find(".expandBtn"), this.$rr = a("#rightRail"), this.$ui = a([this.$rr[0], this.$expand[0]]), this.isExpanded = !1, this.closeOnClick, c = this
        }, e = {
            hide: function (a) {
                d().isExpanded ? d().shrinkVideo() : typeof a == "undefined" || typeof a == "object" ? d().hide({
                    hidePlayer: !1
                }) : parseInt(a) === 27 && d().hide({
                    hidePlayer: !1
                })
            },
            showUI: function () {
                d().showUI(!1)
            },
            clearTimeout: function () {
                d().clearTimeout()
            },
            hideUI: function () {
                d().hideUI()
            },
            expandVideo: function () {
                d().expandVideo()
            },
            handleDialogs: function (a) {
                switch (a.attr("id")) {
                    case "searchDialog":
                        d().hide({
                            hidePlayer: !0,
                            leaveCover: !0
                        });
                        break;
                    case "photoCarouselLightbox":
                        d().hide({
                            hidePlayer: !0,
                            leaveCover: !0,
                            leaveRightRail: !0
                        });
                        break;
                    default:
                        d().hide({
                            hidePlayer: !0,
                            leaveCover: !1
                        })
                }
            }
        };
    d.prototype.wire = function () {
        var b = !1;
        a("#lightboxCover > .close").on("click", e.hide), this.$ui.on("mouseenter", e.clearTimeout).on("mouseleave", e.hideUI), this.$expand.on("click", e.expandVideo), this.showRightRail && comm.listen("player.mouseMove", e.showUI), comm.listen("page.esc", e.hide), comm.listen("player.keyDown", e.hide), comm.listen("dialog.showing", e.handleDialogs), comm.listen("queue.ended", function () {
            b = !0
        }), comm.listen("player.loading", function (a) {
            a.mediaItem.mediaType !== "video" || b ? d().hide() : d().isOpen && d().updateMe(a.mediaItem)
        }), comm.listen("spaceway.page.loading", function () {
            d().hide()
        })
    }, d.prototype.cleanup = function () {
        var c = this;
        this.updateUrl(null, b.videoReferrer), this.$expand.removeAttr("style"), a("#lightboxCover > .close").off("click", e.hide), this.$ui.off("mouseleave", e.hideUI).off("mouseenter", e.clearTimeout), this.$expand.off("click", e.expandVideo), comm.send("rightRail.instance", function (a) {
            a && (a.closeOnClick = c.closeOnClick)
        }), comm.stopListening("page.esc", e.hide), comm.stopListening("player.keyDown", e.hide), comm.stopListening("player.mouseMove", e.showUI), comm.stopListening("dialog.showing", e.handleDialogs)
    }, d.prototype.updateUrl = function (a, b) {
        var c = b || a.detailUrl;
        comm.send("location.href", {
            url: c
        })
    }, d.prototype.updateMe = function (a) {
        this.showUI(a, !0), this.updateLocation ? this.updateUrl(a) : this.updateLocation = !0
    }, d.prototype.show = function (c, d) {
        !b.VideoPlayer.isVideoDetail() && !this.isOpen && (b.videoReferrer = window.location.pathname);
        var e = this,
            f = d || {}, g = f.detailUrl;
        if (c) if (!b.VideoPlayer.isVideoDetail() && !b.VideoPlayer.dialogOpen && !this.isOpen) {
                var h = f.modal,
                    i = f.continuePlay,
                    j = f.updateLocation,
                    k = f.showRightRail;
                this.isOpen = !0, this.updateLocation = typeof j != "undefined" ? j : !0, this.showRightRail = typeof k != "undefined" ? k : !0, this.playerClass = h ? "lightBox modal" : "lightBox", this.coverClass = h ? "video modal" : "video", this.player.$container.removeAttr("style").removeClass("tooltip").addClass(this.playerClass).css("opacity", .01), this.player.closed = !1, a("#lightboxCover").hide().addClass(this.coverClass).removeClass("hide").fadeIn(function () {
                    e.player.$container.animate({
                        opacity: 1
                    })
                }), a("#searchDialog").removeClass("open"), this.showRightRail && comm.send("rightRail.instance", function (a) {
                    a && a.$container.css("z-index", e.rrZindex)
                }), this.wire(), i !== !0 ? this.playVideo(c) : this.updateMe(c)
            } else this.isOpen ? comm.send("player.nowPlaying", function (a) {
                    a.mediaItem && a.mediaItem.mediaType === "video" && a.mediaItem.mediaId !== c.mediaId && e.playVideo(c)
                }) : comm.send("location.href", c.detailUrl);
            else g && comm.send("location.href", g)
    }, d.prototype.hide = function (b) {
        if (this.isOpen) {
            var c = this,
                d = b && b.hidePlayer,
                e = b && b.leaveCover,
                f = b && b.leaveRightRail;
            this.clearTimeout(), this.isOpen = !1, this.player.$container.removeAttr("style").removeClass(this.playerClass).addClass("tooltip"), this.player.hide(), this.player.setSize(), this.player.setVPos(), d !== !0 && this.player.handleShow(), e !== !0 && a("#lightboxCover").addClass("hide"), f !== !0 && (this.closeRightRail(), comm.send("rightRail.instance", function (a) {
                a && a.$container.css("z-index", "")
            })), a("#lightboxCover").removeClass(c.coverClass).removeAttr("style"), this.cleanup()
        }
    }, d.prototype.getVideo = function (a) {}, d.prototype.expandVideo = function () {
        var a = this;
        this.player.$container.animate({
            opacity: .01
        }, function () {
            a.playerClass += " full", a.player.$container.addClass(a.playerClass), a.$expand.hide(), a.player.$container.animate({
                opacity: 1
            }), a.isExpanded = !0
        })
    }, d.prototype.shrinkVideo = function () {
        var a = this;
        this.player.$container.animate({
            opacity: .01
        }, function () {
            a.player.$container.removeClass("full"), a.$expand.show(), a.player.$container.animate({
                opacity: 1
            }), a.isExpanded = !1
        })
    }, d.prototype.playVideo = function (a) {
        b.Player.ready ? comm.send("queue.find.video", a) : comm.listen("player.ready", function () {
            comm.send("queue.find.video", a)
        })
    }, d.prototype.openRightRail = function () {
        comm.send("rightRail.instance", function (a) {
            a && a.open()
        })
    }, d.prototype.renderRightRail = function (a) {
        var c = this;
        a && comm.send("rightRail.instance", function (d) {
            d && (c.closeOnClick = d.closeOnClick, d.closeOnClick = b.User.isLoggedIn, d.info(a))
        })
    }, d.prototype.closeRightRail = function () {
        comm.send("rightRail.instance", function (a) {
            a && a.close()
        })
    }, d.prototype.hideUI = function () {
        var a = this;
        a.uiVisible && b.User.isLoggedIn && (this.clearTimeout(), this.timeout = setTimeout(function () {
            a.closeRightRail(), a.uiVisible = !1, a.$expand.css({
                opacity: 0
            })
        }, this.uiDelay))
    }, d.prototype.showUI = function (a, b) {
        if (b || !this.uiVisible) this.clearTimeout(), this.showRightRail && (b === !0 ? this.renderRightRail(a) : this.openRightRail()), this.uiVisible = !0, this.$expand.css({
                opacity: .8
            }), this.hideUI()
    }, d.prototype.clearTimeout = function () {
        clearTimeout(this.timeout)
    }, comm.listen("videoLightbox.instance", function (a) {
        a(d())
    }, !0), comm.listen("videoLightbox.show", d().show, !0), comm.listen("videoLightbox.hide", d().hide, !0)
})(jQuery, window.Myspace = window.Myspace || {});
var Queue = function (a, b) {
    function h(a) {
        var b = l(a);
        return b.length && (f.removeClass("selected"), f = b.addClass("selected")), b
    }
    function i(a, c) {
        c = c || {}, c.$li = a, c.mediaItem = k(a), c.mode = b, m("load", c)
    }
    function j(a, b) {
        var c = [];
        return a.forEach(function (a, d) {
            try {
                var e = document.createElement("ul");
                e.innerHTML = require("ejs").render(templates["common/views/footer/_queueItem"], {
                    queueItem: a
                }), e.children[0].setAttribute("data-order", b + d), c.push(e.children[0])
            } catch (f) {}
        }), $(c)
    }
    function k(a) {
        var b = a.find(".playBtn"),
            c;
        return b.length && (c = objectify(b)), c
    }
    function l(a) {
        if (typeof a == "object") {
            if (a instanceof $ && a.is("li")) return a;
            if (a instanceof Node && a.tagName == "LI") return $(a)
        } else if (typeof a == "string") return c.filter(a);
        return $()
    }
    function m(a, b) {
        comm.send("player." + a, b)
    }
    function n() {
        p(), s()
    }
    function o() {
        s()
    }
    function p() {
        e = d.find("li"), c.listId = undefined, m("queueChanged", b)
    }
    function q() {
        e.each(function (a, b) {
            b.setAttribute("data-order", a)
        })
    }
    function r(a, c, d) {
        scomm.send("queue." + b + "." + a, c, d)
    }
    function s(a) {
        r("setHtml", d.html(), a)
    }
    function t(a) {
        d.html(a), d.find(".connectButton").removeAttr("data-popover-initialized"), f = d.find("li.selected"), p()
    }
    function u(a) {
        var b = [];
        e.each(function (a, c) {
            b.push(parseInt(c.getAttribute("data-order")))
        }), r("setOrder", b, a)
    }
    function v(a) {
        e.each(function (b, c) {
            c.setAttribute("data-order", a[b])
        })
    }
    function w(a) {
        r("setSelected", c.position, a)
    }
    function x(a) {
        h('li[data-order="' + a + '"]')
    }
    var c = this,
        d = $(a),
        e = d.find("li"),
        f = d.find("li.selected"),
        g;
    q(), this.listId, this.removed = $.noop, this.play = $.noop, this.expand = $.noop, Object.defineProperty(this, "mode", {
        get: function () {
            return b
        }
    }), Object.defineProperty(this, "$ul", {
        get: function () {
            return d
        }
    }), Object.defineProperty(this, "$lis", {
        get: function () {
            return e
        }
    }), Object.defineProperty(this, "$selected", {
        get: function () {
            return f
        }
    }), Object.defineProperty(this, "$previous", {
        get: function () {
            return d.find('li[data-order="' + (this.position - 1) + '"]')
        }
    }), Object.defineProperty(this, "$next", {
        get: function () {
            return d.find('li[data-order="' + (this.position + 1) + '"]')
        }
    }), Object.defineProperty(this, "$first", {
        get: function () {
            return d.find('li[data-order="0"]')
        }
    }), Object.defineProperty(this, "$last", {
        get: function () {
            return d.find('li[data-order="' + (this.length - 1) + '"]')
        }
    }), Object.defineProperty(this, "length", {
        get: function () {
            return e.length
        }
    }), Object.defineProperty(this, "position", {
        get: function () {
            return parseInt(f.attr("data-order"))
        }
    }), Object.defineProperty(this, "media", {
        get: function () {
            var a = [];
            return e.each(function (b, c) {
                a.push(k($(c)))
            }), a
        }
    }), this.set = function (a) {
        var b = j(a, 0);
        return f = $(), d.empty().append(b), n(), g && c.shuffle(), b
    }, this.insert = function (a) {
        if (!this.$next.length) return c.append(a);
        var b = j(a, this.position + 1),
            d = b.length;
        return e.each(function (a, b) {
            var e = parseInt(b.getAttribute("data-order"));
            e > c.position && b.setAttribute("data-order", e + d)
        }), b.insertAfter(f), n(), b
    }, this.append = function (a) {
        var b = j(a, c.length);
        return d.append(b), n(), b
    }, this.remove = function (a) {
        var d = l(a);
        if (d.remove().length) {
            n(), g ? c.shuffle() : c.unshuffle();
            if (d.hasClass("selected")) if (c.length == 0) f = $(), m("unload", b);
                else {
                    var e = parseInt(d.attr("data-order"));
                    e == c.length ? c.previous() : c.select('li[data-order="' + e + '"]')
                }
            c.removed(d)
        }
    }, this.clear = function () {
        d.empty(), n(), m("unload", b)
    }, this.select = function (a, b) {
        var c = h(a);
        return c.length && (w(), i(c, b)), c
    }, this.play = function (a) {
        return this.select(a, {
            play: !0
        })
    }, this.replay = function (a) {
        return this.play(c.$selected, a)
    }, this.previous = function (a) {
        return this.select(this.$previous, a)
    }, this.next = function (a) {
        return this.select(this.$next, a)
    }, this.first = function (a) {
        return this.select(this.$first, a)
    }, this.last = function (a) {
        return this.select(this.$last, a)
    }, this.error = function () {
        f.hasClass("error") || (f.append('<div class="error"><i class="error_24"></i><span>Error Playing</span></div>'), setTimeout(function () {
            f.addClass("error")
        }, 50))
    }, this.filter = function (a) {
        return d.find(a).closest("li")
    }, this.shuffle = function () {
        var a = [],
            b = !! f.length;
        b || a.push(0);
        for (var c = 1; c < this.length; c++) a.push(c);
        for (var d, h, c = a.length; c; d = parseInt(Math.random() * c), h = a[--c], a[c] = a[d], a[d] = h);
        e.each(function (c, d) {
            d.setAttribute("data-order", b && d.className.indexOf("selected") > -1 ? 0 : a.shift())
        }), u(), g = !0
    }, this.unshuffle = function () {
        q(), u(), g = !1
    }, this.resetOrder = function () {
        q()
    }, this.changed = function () {
        n()
    }, this.updated = function () {
        o()
    }, this.sync = function (a) {
        r(a, scomm.hash, localStorage.activePlayer)
    };
    var y = {
        syncHtml: s,
        setHtml: t,
        syncOrder: u,
        setOrder: v,
        syncSelected: w,
        setSelected: x
    };
    scomm.add(function (a, c, d) {
        var e = a.split("."),
            f = e[0],
            g = e[1],
            a = e[2];
        if (f != "queue" || g != b) return;
        y[a](c)
    })
};
(function () {
    function d() {
        var c = a.select('[data-sequence-id="' + b("sequenceId") + '"]', {
            resuming: !0,
            time: b("currentTime"),
            streamStartDateTime: b("streamStartDateTime")
        });
        c.length || (a.length ? a.first({
            resuming: !0
        }) : m("load", {
            mode: "queue"
        }))
    }
    function e() {
        return a.$selected.next().find(".playBtn").attr("data-sequence-id")
    }
    function f(a, b, c) {
        var d = {
            media: []
        }, c = e();
        return b.forEach(function (a) {
            d.media.push({
                mediaType: a.mediaType,
                mediaId: a.mediaId,
                releaseId: a.mediaReleaseId,
                influencerId: a.influencerId,
                entityKey: a.entityKey,
                sourceEntityKey: a.sourceEntityKey || ""
            })
        }), a == "insert" && (isNaN(c) ? a = "append" : d.beforeSequenceId = c), {
            action: a,
            data: d
        }
    }
    function g(c, d, e) {
        e == undefined && (e = !a.length);
        var g = f(c, d);
        k(g.action, g.data, function (c) {
            if ($.isArray(c)) {
                var d;
                h.each(function (a, b) {
                    var e = c[a],
                        f = b.querySelector(".playBtn"),
                        g = b.querySelector(".connectButton");
                    g && (e.isConnected ? g.className.indexOf("connected") == -1 && (g.className += " connected") : g.className.indexOf("connected") > -1 && (g.className = g.className.replace("connected", "").replace("  ", " ").trim()), g.setAttribute("data-is-connected", !! e.isConnected)), f && (f.setAttribute("data-sequence-id", e.sequenceId), f.setAttribute("data-is-connected", !! e.isConnected), e.sourceName && e.sourceUrl && (f.setAttribute("data-source-name", e.sourceName), f.setAttribute("data-source-url", e.sourceUrl)), b.className.indexOf("selected") > -1 && (d = objectify($(f))))
                }), a.updated(), d && m("state", {
                    mediaItem: d
                }), b({
                    sequenceId: a.$selected.find(".playBtn").attr("data-sequence-id")
                })
            }
        });
        var h = a[g.action](d);
        e && a.play(g.action == "set" ? '[data-order="0"]' : h.first())
    }
    function h(a, b) {
        var c = {}, d = e();
        return b.albumId ? c.albumId = b.albumId : b.playlistId && (c.playlist = {
            playlistId: b.playlistId,
            profileId: b.profileId
        }), a == "insert" && (isNaN(d) ? a = "append" : c.beforeSequenceId = d), b.influencerId && (c.influencerId = b.influencerId), {
            action: a,
            data: c
        }
    }
    function i(b, c, d) {
        d = d || !a.length, l("loading", c);
        var e = h(b, c);
        k(e.action, e.data, function (b) {
            if ($.isArray(b)) {
                var c = a[e.action](b);
                d && a.play(e.action == "set" ? '[data-order="0"]' : c.first())
            }
            l("loaded")
        }, function () {
            l("loaded")
        })
    }
    function j(c) {
        var d = objectify(c.find(".playBtn")),
            e = {
                mediaType: d.mediaType,
                mediaId: d.mediaId,
                sequenceId: d.sequenceId
            }, f = c.next().find(".playBtn").attr("data-sequence-id");
        f && (e.beforeSequenceId = f), k("move", e), b("shuffled") || a.resetOrder(), a.changed()
    }
    function k(a, b, c, d) {
        $.save({
            url: "/ajax/music/queue/" + a,
            data: b,
            success: c,
            error: d
        })
    }
    function l(a, b) {
        c.broadcast(a, b), scomm.send && scomm.send("queue.broadcast." + a, b)
    }
    function m(a, b) {
        comm.send("player." + a, b)
    }
    function n(a, b) {
        comm.send("track", new Tracking("playerQueue", a, b))
    }
    var a = new Queue("#queue .list.queue", "queue"),
        b = new CookieHelper("player");
    a.$ul.on("click", function (b) {
        var c = $(b.target),
            d = c.closest("li"),
            e = d.find(".playBtn"),
            f = e.attr("data-type");
        if (!d.length || c.is("a") && (f != "video" || !c.parent().is("h6"))) return;
        var g = c.closest(".connectButton");
        if (g.length) {
            n("connect", g.hasClass("connected") ? "disconnect" : "connect");
            return
        }
        if (c.is("a") && f === "video" || c.hasClass("expand")) {
            var h = objectify(e);
            comm.send("videoLightbox.instance", function (a) {
                a ? a.show(h) : (context.pfc !== "videodetail" && (Myspace.videoReferrer = window.location.pathname), comm.send("location.href", h.detailUrl))
            }), c.hasClass("expand") && n("expand")
        } else if (c.hasClass("remove")) a.remove(d), n("remove", f);
        else if (d.hasClass("selected")) {
            var i = e.hasClass("playing") ? "pause" : "resume";
            m(i, f), n(i, f)
        } else n("play", f), a.play(d);
        return !1
    });
    var c = comm.own("queue", {
        set: function (b) {
            b.listId != a.listId && (g("set", b.media, !1), a.listId = b.listId), b.selected ? a.play('[data-uid="' + b.selected.uid + '"]') : a.first({
                play: !0
            })
        },
        "play.song": function (a) {
            g("insert", [a], !0)
        },
        "insert.song": function (a) {
            g("insert", [a])
        },
        "append.song": function (a) {
            g("append", [a])
        },
        "find.video": function (b) {
            var c = a.filter('[data-media-id="' + b.mediaId + '"]');
            c.length ? a.play(c) : this["play.video"](b)
        },
        "play.video": function (a) {
            g("insert", [a], !0)
        },
        "insert.video": function (a) {
            g("insert", [a])
        },
        "append.video": function (a) {
            g("append", [a])
        },
        "set.album": function (a) {
            i("set", a, !0)
        },
        "play.album": function (a) {
            i("insert", a, !0)
        },
        "insert.album": function (a) {
            i("insert", a)
        },
        "append.album": function (a) {
            i("append", a)
        },
        "set.mixtape": function (a) {
            i("set", a, !0)
        },
        "play.mixtape": function (a) {
            i("insert", a, !0)
        },
        "insert.mixtape": function (a) {
            i("insert", a)
        },
        "append.mixtape": function (a) {
            i("append", a)
        },
        clear: function () {
            a.clear(), b({
                sequenceId: -1
            }), k("clear")
        },
        previous: function () {
            if (b("shuffled")) {
                this.next();
                return
            }
            var c = !a.previous().length;
            c && (b("repeat") != "off" ? a.last() : a.replay())
        },
        next: function () {
            var c = !a.next().length;
            c && (b("shuffled") == 1 ? (a.shuffle(), a.next()) : a.first({
                paused: b("repeat") == "off"
            }))
        },
        end: function () {
            if (b("repeat") == "one") a.replay();
            else {
                var d = !a.next().length;
                d && (c.broadcast("ended"), a.first({
                    paused: b("repeat") == "off"
                }))
            }
        },
        shuffle: function (b) {
            b ? a.shuffle() : a.unshuffle()
        },
        error: function (b) {
            a.error(), m("pause")
        },
        media: function (b) {
            b(a.media)
        },
        activate: function () {
            d()
        }
    });
    comm.listen({
        player: {
            "+sync": function () {
                a.sync("syncOrder")
            },
            "+activate": function () {
                b("mode") == "queue" && d()
            },
            "+activated": function () {
                b("shuffled") && a.shuffle()
            },
            "+loading": function (a) {
                a.mode == "queue" && localStorage.activePlayer == scomm.hash && b({
                    sequenceId: a.mediaItem.sequenceId,
                    currentTime: a.time
                })
            }
        }
    }), a.removed = function (c) {
        a.length == 0 && b("mode") == "queue" && m("pause");
        var d = c.find(".playBtn");
        k("remove", {
            media: {
                mediaType: d.attr("data-media-type"),
                mediaId: d.attr("data-media-id"),
                sequenceId: d.attr("data-sequence-id")
            }
        })
    }, scomm.add(function (a, b, d) {
        var e = a.split("."),
            f = e[0],
            a = e[1],
            g = e[2];
        if (f != "queue") return;
        switch (a) {
            case "broadcast":
                c.broadcast(g, b);
                break;
            default:
                comm.send("queue." + a, b)
        }
    })
})();
(function () {
    function e() {
        var c = a.select('[data-media-id="' + b("radioMediaId") + '"]', {
            time: b("radioCurrentTime"),
            streamStartDateTime: b("radioStreamStartDateTime")
        });
        c.length || (a.length ? a.first() : comm.send("queue.activate"))
    }
    function f(b) {
        c = i(1, function (c) {
            $.isArray(c.songs) && c.songs.length ? (a.append(c.songs), b && a.next(), a.$next.length || f()) : g()
        }, function () {
            g()
        })
    }
    function g() {
        Myspace.Error({
            text: "Oops, we couldn't retrieve songs for this station at this time. Please try again later.",
            yes: {
                text: "OK"
            },
            no: !1
        })
    }
    function h(a, b) {
        comm.send("player." + a, b)
    }
    function i(a, c, d) {
        return $.save({
            url: "/ajax/music/radio",
            data: {
                radioEntity: b("radioEntity"),
                max: a
            },
            success: c,
            error: d
        })
    }
    function j(a, b) {
        d.broadcast(a, b), scomm.send && scomm.send("radio.broadcast." + a, b)
    }
    function k(a, b, c) {
        comm.send("track", new Tracking(a, b, c))
    }
    var a = new Queue("#queue ul.list.radio", "radio"),
        b = new CookieHelper("player"),
        c;
    a.$ul.on("click", function (a) {
        var b = $(a.target),
            c = b.closest("li");
        if (!c.length || b.is("a")) return;
        var d = b.closest(".connectButton");
        if (d.length) {
            k("playerQueue", "connect", d.hasClass("connected") ? "disconnect" : "connect");
            return
        }
        if (c.hasClass("selected")) {
            var e = c.find(".playBtn"),
                f = e.hasClass("playing") ? "pause" : "resume",
                g = e.attr("data-type");
            h(f), k("playerQueue", f, g)
        }
        return !1
    });
    var d = comm.own("radio", {
        activate: function () {
            e()
        },
        start: function (d) {
            var e = d.radioEntity || d.radioStationEntityKey || d.genreRadioStationEntityKey || "";
            if (!Myspace.User.isLoggedIn) {
                comm.send("login.prompt", {
                    action: "playRadio",
                    object: e
                });
                return
            }
            b({
                radioEntity: e,
                radioCurrentTime: 0
            }), j("starting", d), c && c.abort(), c = i(2, function (c) {
                c.radioEntity && (d.radioEntity = c.radioEntity, b({
                    radioEntity: c.radioEntity
                })), $.isArray(c.songs) && c.songs.length ? (a.set(c.songs), a.first({
                    play: !0
                })) : g(), j("started", d)
            }, function () {
                g(), j("started", d)
            })
        },
        clear: function () {
            a.$selected.prevAll().remove(), a.changed(), a.unshuffle()
        },
        next: function () {
            var b = !a.next().length;
            b ? f(!0) : a.$next.length || f()
        },
        end: function () {
            this.next()
        },
        error: function () {
            a.error(), h("pause")
        },
        media: function (b) {
            b(a.media)
        }
    });
    comm.listen({
        player: {
            "+sync": function (c) {
                b("mode") == "radio" && a.sync("syncHtml")
            },
            "+activate": function () {
                b("mode") == "radio" && e()
            },
            "+loading": function (a) {
                a.mode == "radio" && localStorage.activePlayer == scomm.hash && b({
                    radioMediaType: a.mediaItem.mediaType,
                    radioMediaId: a.mediaItem.mediaId,
                    radioCurrentTime: a.time
                })
            }
        }
    }), scomm.add(function (a, b, c) {
        var e = a.split("."),
            f = e[0],
            a = e[1],
            g = e[2];
        if (f != "radio") return;
        switch (a) {
            case "broadcast":
                d.broadcast(g, b);
                break;
            default:
                comm.send("radio." + a, b)
        }
    })
})();
(function () {
    var a = new Queue("#queue .list.preview", "preview"),
        b = new CookieHelper("player");
    a.$ul.on("click", function (b) {
        var c = $(b.target),
            d = c.closest("li");
        if (!d.length || c.is("a") || c.closest(".connectButton").length) return;
        if (c.hasClass("expandBtn")) context.pfc !== "videodetail" && (Myspace.videoReferrer = window.location.pathname), comm.send("location.href", d.find(".playBtn").attr("data-detail-url"));
        else if (c.hasClass("remove")) a.remove(d);
        else if (d.hasClass("selected")) {
            var e = d.find(".playBtn").hasClass("playing");
            player(e ? "pause" : "resume")
        } else a.play(d);
        return !1
    });
    var c = comm.own("preview", {
        set: function (b) {
            b.listId != a.listId && (a.set(b.media), a.listId = b.listId), a.play('[data-uid="' + b.selected.uid + '"]')
        },
        "play.song": function (b) {
            a.play(a.insert([b]))
        },
        "find.video": function (b) {
            var c = a.filter('[data-media-id="' + b.mediaId + '"]');
            c.length ? a.play(c) : this["play.video"](b)
        },
        "play.video": function (b) {
            a.play(a.insert([b]))
        },
        previous: function () {
            var b = !a.previous().length;
            b && a.replay()
        },
        next: function () {
            var b = !a.next().length;
            b && a.first({
                paused: !0
            })
        },
        end: function () {
            var b = !a.next().length;
            b && (c.broadcast("ended"), a.first({
                paused: !0
            }))
        }
    });
    comm.listen({
        player: {
            "+sync": function () {
                b("mode") == "preview" && a.sync("syncHtml")
            },
            "+activate": function () {
                b("mode") == "preview" && (a.$selected.length ? a.play(a.$selected) : comm.send("queue.activate"))
            }
        }
    }), a.removed = function () {
        a.length == 0 && b("mode") == "preview" && comm.send("queue.activate")
    }
})();
(function () {
    function volume(a) {
        player.volume(a), sugr.volume(a), _comm.broadcast("volumeChanged", a)
    }
    function mute(a) {
        var b = player.mute(a);
        sugr.mute(b), _comm.broadcast(b ? "muted" : "unmuted")
    }
    function getTime() {
        switch (cookie("mode")) {
            case "radio":
                return cookie("radioCurrentTime");
            case "queue":
                return cookie("currentTime");
            case "preview":
                return previewCurrentTime
        }
        return 0
    }
    function setTime(a) {
        switch (cookie("mode")) {
            case "radio":
                cookie({
                    radioCurrentTime: a
                });
                break;
            case "queue":
                cookie({
                    currentTime: a
                });
                break;
            case "preview":
                previewCurrentTime = a
        }
    }
    function getStreamStartDateTime() {
        switch (cookie("mode")) {
            case "radio":
                return cookie("radioStreamStartDateTime");
            case "queue":
                return cookie("streamStartDateTime");
            case "preview":
                return previewStreamStartDateTime
        }
    }
    function setStreamStartDateTime(a) {
        mediaItem.streamStartDateTime = a;
        switch (cookie("mode")) {
            case "radio":
                cookie({
                    radioStreamStartDateTime: a
                });
                break;
            case "queue":
                cookie({
                    streamStartDateTime: a
                });
                break;
            case "preview":
                previewStreamStartDateTime = a
        }
    }
    function mode(a, b) {
        comm.send(cookie("mode") + "." + a, b)
    }
    function broadcast(a, b) {
        _comm.broadcast(a, b), send("broadcast." + a, b)
    }
    function getState(a) {
        return $.extend({
            mode: cookie("mode"),
            mediaItem: mediaItem,
            paused: cookie("paused"),
            time: getTime(),
            tsl: tsl
        }, a)
    }
    function getVideo(a) {
        a.mediaType == "audio" && a.videoId && (videoRequest = $.save({
            url: "/ajax/videos",
            data: {
                videoIds: [a.videoId]
            },
            success: function (b) {
                $.isArray(b) && b.length && (a.video = b[0], broadcast("videoPreview", a.video))
            },
            error: function () {}
        }))
    }
    function loadAd(a) {
        player.swf.pauseCurrentTrack();
        if (!context.integratedAdMediaPlayer) sugr.loadAd(mediaItem.genreId, context.ads.msd);
        else {
            var b = adMediaType == "video" && focused !== !1;
            sugr.loadAd(mediaItem.genreId, context.ads.msd, b)
        }
    }
    function stopAd() {
        sugr.isPlaying ? sugr.stopAd() : send("stopAd")
    }
    function updateMediaItem(a) {
        mediaItem.video && (a.video = mediaItem.video);
        for (var b in a) b != "streamUrl" && (mediaItem[b] = a[b])
    }
    function setMediaItem(a) {
        mediaItem && (prevMediaItem = mediaItem), mediaItem = a, generateAdMediaType()
    }
    function generateAdMediaType() {
        var a = mediaItem.mediaType,
            b;
        prevMediaItem ? b = prevMediaItem.mediaType : b = a;
        var c = b + "_" + a,
            d = context.adPlayer ? context.adPlayer.videoAdsRatio[c] : 0;
        adMediaType = Math.random() > d ? "audio" : "video", adMediaType == "audio" && (b == "video" || a == "video") && (adMediaType = null), log("Video ads ratio: " + d + ", next ad type: " + adMediaType)
    }
    function getAdsFirstAdAfter() {
        return context.adPlayer ? context.adPlayer.firstAdAfter : context.audioAds.firstAdAfter
    }
    function getAdsSubsequentAdsAfter() {
        return context.adPlayer ? context.adPlayer.subsequentAdsAfter : context.audioAds.subsequentAdsAfter
    }
    function getAdsSkippingEnabled() {
        return context.adPlayer ? adMediaType == "video" ? context.adPlayer.videoAds.skippingEnabled : context.adPlayer.audioAds.skippingEnabled : context.audioAds.skippingEnabled
    }
    function getAdsUnskippableDuration() {
        return context.adPlayer ? adMediaType == "video" ? context.adPlayer.videoAds.unskippableDuration : context.adPlayer.audioAds.unskippableDuration : context.audioAds.unskippableDuration
    }
    function getAdsEnabled(a) {
        return a ? a == "audio" ? context.adPlayer ? context.adPlayer.audioAds.enabled : context.audioAds.enabled : context.adPlayer ? context.adPlayer.videoAds.enabled : !1 : context.adPlayer ? context.adPlayer.audioAds.enabled || context.adPlayer.videoAds.enabled : context.audioAds.enabled
    }
    function ready(a) {
        ready[a] = !0, log(a, "ready.");
        var b = context.integratedAdMediaPlayer ? ready.swf && ready.scomm : ready.swf && ready.scomm && ready.sugr;
        b && (log("player ready"), Myspace.Player.ready = !0, _comm.broadcast("ready"), player.active || checkActive(function () {
            _comm.broadcast("sync")
        }, function () {
            Number(cookie("at")) > 0 && cookie({
                at: getAdsFirstAdAfter()
            }), activate()
        }))
    }
    function send(a, b, c, d, e) {
        scomm.send && scomm.send("player." + a, b, c, d, e)
    }
    function checkActive(a, b) {
        log("checking for active player.");
        try {
            localStorage.activePlayer ? player.active || send("state", null, localStorage.activePlayer, function () {
                log("active player not responding."), delete localStorage.activePlayer, b && b()
            }, function () {
                log("active player found. syncing."), a && a()
            }) : (log("no active player."), b && b())
        } catch (c) {}
    }
    function activate() {
        log("activate player."), _comm.broadcast("activate")
    }
    function activating() {
        send("deactivate");
        try {
            player.active || (log("activating player."), localStorage.activePlayer = scomm.hash, _comm.broadcast("activated"), log("player activated."))
        } catch (a) {}
    }
    function deactivate() {
        ad.isPlaying && (onAdStop = undefined), player.swf.pauseCurrentTrack();
        try {
            player.active && (delete localStorage.activePlayer, _comm.broadcast("deactivated"), log("player deactivated."))
        } catch (a) {}
    }
    function check(a) {
        a.forEach(function (a) {
            a != scomm.hash && send("check", null, a, function () {
                remove(a)
            })
        })
    }
    function save(a) {
        try {
            localStorage.players = JSON.stringify(a)
        } catch (b) {}
    }
    function remove(a) {
        var b = instances(),
            c = b.indexOf(a);
        c > -1 && (b.splice(c, 1), save(b))
    }
    function instances() {
        var a = [];
        try {
            a = JSON.parse(localStorage.players)
        } catch (b) {}
        return $.isArray(a) ? a : []
    }
    function log() {
        context.reportSongEnabled && console.log.apply(console, arguments)
    }
    var mediaItem, prevMediaItem, tsl = 0,
        ending, focused, cookie = new CookieHelper("player"),
        player = Myspace.Player,
        sugr = Myspace.Sugr,
        loading, onResume, onAdStop, previewCurrentTime, previewStreamStartDateTime, videoRequest, adMediaType, ad = {
            isPlaying: undefined,
            skipped: undefined
        }, switchboard = {
            load: function (a) {
                if (a) {
                    activating(), a.mode && a.mode != cookie("mode") && (cookie({
                        mode: a.mode
                    }), broadcast("mode", a.mode));
                    if (!a.mediaItem) {
                        player.pause();
                        return
                    }
                    Myspace.User.isLoggedIn || delete a.mediaItem.streamUrl;
                    var b = function () {
                        mediaItem && broadcast("stopped", getState()), setMediaItem(a.mediaItem), mediaItem.streamStartDateTime = a.streamStartDateTime, a.paused != undefined && cookie({
                            paused: a.paused
                        }), a.play != undefined && cookie({
                            paused: !a.play
                        }), setTime(a.time || 0), tsl = 0;
                        var b = function () {
                            loading = !0, broadcast("loading", getState()), a.mediaItem.streamUrl ? player.load(a.mediaItem, a.time) : switchboard.pause(), getVideo(mediaItem)
                        };
                        ad.isPlaying ? (onAdStop = b, broadcast("preloading", getState()), ad.skipped = !0, cookie("paused") || switchboard.resume()) : getAdsEnabled() && !Number(cookie("at")) && (mediaItem.mediaType == "audio" || context.adPlayer) && adMediaType ? (onAdStop = b, broadcast("preloading", getState()), cookie("paused") ? onResume = loadAd : loadAd()) : (onAdStop = undefined, b())
                    };
                    a.mediaItem.streamUrl ? b() : $.save({
                        url: "/ajax/streamurl",
                        data: {
                            mediaType: a.mediaItem.mediaType,
                            mediaId: a.mediaItem.mediaId
                        },
                        loginPromptSettings: {
                            action: "play",
                            object: a.mediaItem.entityKey
                        },
                        success: function (b) {
                            a.mediaItem.streamUrl = b
                        },
                        error: a.resuming ? function () {
                            a.play = !1
                        } : undefined,
                        errorCallback: function () {
                            a.play = !1
                        },
                        complete: function () {
                            b()
                        }
                    })
                }
            },
            unload: function (a) {
                a == cookie("mode") && (player.pause(), setTime(0), tsl = 0, mediaItem = undefined, broadcast("unloaded", getState()))
            },
            pause: function () {
                player.active ? (cookie({
                    paused: !0
                }), ad.isPlaying ? broadcast("pauseAd") : player.pause(), broadcast("paused", getState())) : send("pause", null, localStorage.activePlayer)
            },
            resume: function () {
                if (player.active) {
                    if (!mediaItem.streamUrl) {
                        comm.send("login.prompt", {
                            action: "play",
                            object: mediaItem.entityKey
                        });
                        return
                    }
                    cookie({
                        paused: !1
                    }), onResume ? (onResume(), onResume = undefined) : ad.isPlaying ? broadcast("resumeAd") : player.resume(), broadcast("resumed", getState())
                } else send("resume", null, localStorage.activePlayer)
            },
            playPause: function () {
                cookie("paused") ? this.resume() : this.pause()
            },
            seek: function (a) {
                player.active ? (setTime(a), player.seek(a), broadcast("seeked", a)) : send("seek", a, localStorage.activePlayer)
            },
            volume: function (a) {
                volume(a), send("volume", a)
            },
            mute: function (a) {
                mute(a), send("mute", a)
            },
            previous: function () {
                mode("previous")
            },
            next: function () {
                ad.isPlaying ? stopAd() : mode("next")
            },
            shuffle: function () {
                var a = !cookie("shuffled");
                cookie({
                    shuffled: a
                }), mode("shuffle", a), broadcast("shuffleChanged", a)
            },
            repeat: function () {
                var a = cookie("repeat") == "off" ? "all" : cookie("repeat") == "all" ? "one" : "off";
                cookie({
                    repeat: a
                }), broadcast("repeatChanged", a)
            },
            nowPlaying: function (a) {
                $.isFunction(a) && a(getState())
            },
            activate: function () {
                activate()
            },
            deactivate: function () {
                deactivate()
            },
            tryActivate: function () {
                focused ? activate() : setTimeout(function () {
                    scomm.hash == instances()[0] && checkActive(undefined, activate)
                }, 100)
            },
            queueChanged: function (a) {
                _comm.broadcast("queueChanged", a)
            },
            state: function (a) {
                a && a.mediaItem && updateMediaItem(a.mediaItem), broadcast("state", getState(a))
            },
            loadAd: function () {
                loadAd()
            },
            stopAd: function () {
                sugr.isPlaying && sugr.stopAd()
            },
            nextAdAfter: function (a) {
                isNaN(a) || cookie({
                    at: a
                })
            },
            adClicked: function () {
                broadcast("onAdClick")
            },
            incognito: function (a) {
                a == undefined && (a = !cookie("incognito")), cookie({
                    incognito: a
                }), broadcast("incognitoChanged", a)
            }
        }, _comm = comm.own("player", switchboard);
    comm.listen("page.changed", function () {
        mediaItem && _comm.broadcast("state", getState())
    }, !0), comm.listen({
        player: {
            "+adStarted": function () {
                ad.isPlaying = !0, ad.skipped = !1
            },
            "+adStopped": function () {
                ad.isPlaying = !1, player.active && (cookie({
                    at: getAdsSubsequentAdsAfter()
                }), onAdStop && onAdStop()), onAdStop = undefined
            },
            "+adRemainingTime": function (a) {
                ad.skipped && a.nonSkipTime == 0 && stopAd()
            },
            "+loading": function () {
                videoRequest && videoRequest.abort()
            },
            "+onAdClick": function () {
                sugr.isPlaying && sugr.sendAdClickTracking()
            },
            "+resumeAd": function () {
                sugr.isPlaying && sugr.resumeAd()
            },
            "+pauseAd": function () {
                sugr.isPlaying && sugr.pauseAd()
            }
        }
    }), context.integratedAdMediaPlayer || $.extend(sugr, {
        ready: function () {
            sugr.volume(cookie("volume")), ready("sugr")
        },
        adStarted: function (a) {
            sugr.isPlaying = !0, ad.clickThroughUrl = a, ad.enableSkipAfter = getAdsSkippingEnabled() && getAdsUnskippableDuration(), broadcast("adStarted", {
                clickThroughUrl: ad.clickThroughUrl,
                enableSkipAfter: ad.enableSkipAfter
            })
        },
        adStopped: function () {
            sugr.isPlaying = !1, broadcast("adStopped")
        },
        adDuration: function (a) {
            ad.duration = a, broadcast("adDuration", a)
        },
        adRemainingTime: function (a, b) {
            ad.isPlaying && (ad.remainingTime = a, ad.enableSkipAfter = getAdsSkippingEnabled() && Math.max(getAdsUnskippableDuration() - b, 0), broadcast("adRemainingTime", {
                remainingTime: a,
                enableSkipAfter: ad.enableSkipAfter
            }))
        }
    }), $.extend(player, {
        onPlayerLoaded: function (a) {
            Myspace.Player.version = a, cookie("mute") ? this.mute(!0) : this.volume(cookie("volume")), ready("swf")
        },
        onSongLoaded: function (a, b, c) {
            loading = !1, broadcast("loaded", getState())
        },
        onPlayingNewTrack: function () {},
        onPlayStarted: function () {
            mediaItem.streamStartDateTime || setStreamStartDateTime((new Date).toISOString())
        },
        onPausingCurrentTrack: function () {},
        onResumePlay: function () {},
        onCurrentTime: function (a, b, c) {
            if (loading) return;
            var d = getTime();
            if (d < a) {
                var e = a - d;
                tsl += e, mediaItem.mediaType == "audio" && cookie({
                    at: Math.max(cookie("at") - e, 0)
                })
            }
            setTime(a), broadcast("time", {
                time: a,
                tsl: tsl,
                buffer: b,
                backBuffer: c
            })
        },
        onStop: function (a) {
            if (ending) return;
            ending = !0, cookie({
                originalStreamUTCDateTime: ""
            }), broadcast("ended", getState()), mediaItem = undefined, mode("end"), setTimeout(function () {
                ending = !1
            }, 2e3)
        },
        onError: function (a) {
            a.indexOf("stream rejected") > -1 && mode("error", a)
        },
        displayAd: function (a, b) {},
        setCurrentPlayTime: function (a) {
            broadcast("time", {
                time: a,
                tsl: tsl
            })
        },
        onVolumeChange: function (a) {},
        onScrub: function (a) {},
        stopAdDisplay: function () {},
        onDurationReceived: function (a) {
            mediaItem.duration = a, broadcast("duration", a)
        },
        mouseMove: function (a, b) {
            _comm.broadcast("mouseMove", {
                x: a,
                y: b
            })
        },
        onClick: function (a, b, c) {
            _comm.broadcast("onClick", {
                x: a,
                y: b,
                mediaInfo: c
            });
            if (c && c.isAd && c.mediaType == "video" && ad && ad.clickThroughUrl) {
                var d = ad.clickThroughUrl.indexOf(document.domain) == -1 && ad.clickThroughUrl.indexOf("new.myspace.com") == -1;
                d && comm.send("player.pause")
            }
        },
        keyDown: function (a) {
            _comm.broadcast("keyDown", a)
        },
        onClose: function () {
            log("swf onClose")
        },
        onTimeout: function () {
            log("swf onTimeout")
        },
        adLoading: function (a) {
            log("swf ad loading"), broadcast("adLoading", {
                isVideo: a
            })
        },
        adLoaded: function () {
            log("swf ad loaded"), broadcast("adLoaded", {
                isVideo: isVideo
            })
        },
        adStarted: function (a, b, c) {
            log('swf ad started, adInfo = "' + c + '"'), sugr.isPlaying = !0, ad.clickThroughUrl = a, ad.enableSkipAfter = getAdsSkippingEnabled() && getAdsUnskippableDuration(), broadcast("adStarted", {
                clickThroughUrl: ad.clickThroughUrl,
                enableSkipAfter: ad.enableSkipAfter,
                isVideo: b,
                adInfo: c
            })
        },
        adStopped: function (a) {
            sugr.isPlaying = !1, broadcast("adStopped", {
                isVideo: a
            })
        },
        adDuration: function (a) {
            ad.duration = a, broadcast("adDuration", a)
        },
        adRemainingTime: function (a, b) {
            ad.isPlaying && (ad.remainingTime = a, ad.enableSkipAfter = getAdsSkippingEnabled() && Math.max(getAdsUnskippableDuration() - b, 0), broadcast("adRemainingTime", {
                remainingTime: a,
                enableSkipAfter: ad.enableSkipAfter
            }))
        }
    }), scomm.add(function (cmd, data, sender) {
        var parts = cmd.split("."),
            owner = parts[0],
            fromMode = parts[1],
            cmd = parts[2];
        if (owner != "queue" || fromMode != mode) return;
        eval(cmd)(data)
    }), scomm.add(function (a, b, c) {
        var d = a.split("."),
            e = d[0],
            a = d[1],
            f = d[2];
        if (e != "player") return;
        b && b.mediaItem && setMediaItem(b.mediaItem);
        switch (a) {
            case "ad":
                ad = b, ad.isPlaying && (_comm.broadcast("adStarted", {
                    clickThroughUrl: ad.clickThroughUrl,
                    enableSkipAfter: ad.enableSkipAfter
                }), _comm.broadcast("adDuration", ad.duration), _comm.broadcast("adRemainingTime", {
                    remainingTime: ad.remainingTime,
                    enableSkipAfter: ad.enableSkipAfter
                }));
                break;
            case "state":
                send("broadcast.state", getState(), c), mediaItem.video && send("broadcast.videoPreview", mediaItem.video, c), send("ad", ad, c);
                break;
            case "broadcast":
                _comm.broadcast(f, b);
                break;
            case "volume":
                volume(cookie("volume"));
                break;
            case "mute":
                mute(cookie("mute"));
                break;
            default:
                comm.send("player." + a, b)
        }
    }), scomm.ready(function () {
        var a = instances();
        a.unshift(scomm.hash), save(a), check(a), ready("scomm")
    }), Object.defineProperty(player, "active", {
        get: function () {
            try {
                return localStorage.activePlayer == scomm.hash
            } catch (a) {
                return !0
            }
        }
    }), $(window).on("beforeunload", function () {
        try {
            player.active && (delete localStorage.activePlayer, send("tryActivate")), remove(scomm.hash)
        } catch (a) {}
    }).on("focus", function () {
        focused = !0
    }).on("blur", function () {
        focused = !1
    })
})();
(function () {
    function h(a) {
        return !d.find(".list." + a + " li").length
    }
    function i(a) {
        return d.find(".list." + a)
    }
    function j(a) {
        $("#save_queue, #clear_queue").attr("disabled", a == undefined || a ? null : "disabled")
    }
    function k(a) {
        var b = $("#queue .list li.selected:visible");
        if (f.is(":animated") || !b.length) return;
        var c = f.offset().left,
            d = f.outerWidth(),
            e = b[0].offsetLeft,
            g = b.position().left,
            h = b.width(),
            i = b.outerWidth();
        (a || g < c || g + h > c + d) && f.animate({
            scrollLeft: e - c - d / 2 + i / 2
        }, 400)
    }
    function l(a, b, c) {
        comm.send("track", new Tracking(a, b, c))
    }
    var a, b, c = $("#footer"),
        d = $("#queue"),
        e = $("#queue .options"),
        f = $("#queue .horizontal"),
        g = $("#station");
    comm.listen({
        player: {
            "+ready": function () {
                if (queryString.play == "1" && context.pfc == "song") {
                    var a = $("#song .mediaItems .playBtn").first();
                    a.length && comm.send("queue.play.song", objectify(a))
                } else k(!0)
            },
            "+mode": function (a) {
                a == "preview" && (comm.send("drawer.message", "Previewing..."), setTimeout(function () {
                    comm.send("drawer.message")
                }, 500)), j(!h(a))
            },
            "+loading": function (a) {
                k()
            },
            "+queueChanged": function (a) {
                c.hasClass(a) && c.toggleClass("empty", h(a)), comm.send("page.changed", i(a)), j(!h(a))
            },
            "+adStarted": function (a) {
                comm.send("drawer.cover", a.nonSkipTime > 0 ? "Skip in " + Math.ceil(a.nonSkipTime) + " seconds..." : "")
            },
            "+adRemainingTime": function (a) {
                comm.send("drawer.cover", a.nonSkipTime > 0 ? "Skip in " + Math.ceil(a.nonSkipTime) + " seconds..." : "")
            },
            "+adStopped": function (a) {
                comm.send("drawer.cover")
            }
        },
        queue: {
            "+loading": function (a) {
                var b = "Loading";
                if (a && a.title) {
                    b += " " + a.title;
                    if (a.artistName || a.owner) b += " by " + (a.artistName || a.owner)
                }
                b += "...", comm.send("drawer.message", b)
            },
            "+loaded": function () {
                comm.send("drawer.panel", "queue"), comm.send("drawer.message")
            }
        },
        radio: {
            "+starting": function (c) {
                comm.send("drawer.message", "Starting " + (c.title || c.name || "") + " Radio..."), a = !1, b = setTimeout(function () {
                    b = null, a && comm.send("drawer.message")
                }, 2e3), g.find("img").attr("src", c.imageUrl), g.find("h6 a").text(c.title || c.name)
            },
            "+started": function (c) {
                a = !0, comm.send("drawer.panel", "queue"), b || comm.send("drawer.message")
            }
        },
        drawer: {
            "+opened": function (a) {
                a == "queue" && k(!0)
            },
            "+panel": function (a) {
                a == "queue" && k(!0)
            }
        }
    }), e.on("click", function (a) {
        var b = $(a.target).closest("button");
        if (b.is("[disabled]")) return;
        switch (b.attr("id")) {
            case "full_queue":
                spaceway.href = "/queue", l("playerQueue", "fullQueue", "clicked");
                break;
            case "history":
                spaceway.href = "/history", l("playerQueue", "history", "clicked");
                break;
            case "save_queue":
                l("playerQueue", "save", "clicked"), comm.send(Cookies.player.values.mode + ".media", function (a) {
                    comm.send("mix.addItems", a)
                });
                break;
            case "clear_queue":
                l("playerQueue", "clear", "clicked");
                var c;
                Myspace.Confirm({
                    text: "Are you sure you want to clear your queue?",
                    yes: {
                        text: "Yes",
                        onClick: function () {
                            comm.send(Cookies.player.values.mode + ".clear"), c = !0
                        }
                    },
                    no: {
                        text: "No"
                    }
                }), comm.listen("dialog.hiding", d);

                function d() {
                    l("playerQueue", "clear", c ? "confirmed" : "cancelled"), comm.stopListening("dialog.hiding", d)
                }
        }
    })
})();
var Myspace = Myspace || {};
Myspace.Mixes = function (a) {
    function d(a, b) {
        var c = objectify(b.find(".playBtn"));
        return c.title
    }
    function e(a, b) {
        b.parent().addClass("dragged")
    }
    function f(a, b) {
        b.parent().removeClass("dragged")
    }
    function g(a, b) {
        var c, d = b.find(".playBtn").data("sequence-id"),
            e = b.next().find(".playBtn").data("sequence-id");
        d == 0 ? c = b.find(".playBtn").data("playlist-id") : c = d;
        var f = {
            playlistId: c,
            beforeSequenceId: e
        };
        o("reorder"), comm.send("mix.move", f)
    }
    function h(c) {
        var d = a(c);
        b.find(".newMix").after(d), Myspace.DragDrop.addDroppables(d)
    }
    function i(a, c) {
        var d = b.find('.mix [data-playlist-id="' + a + '"]').closest("li");
        d.find(".mixCover").removeClass("collage").html('<img src="' + c[3].url + '" />')
    }
    function j(a) {
        b.find('.mix [data-playlist-id="' + a + '"]').closest("li").addClass("noMedia")
    }
    function k(a) {
        b.find('.mix [data-playlist-id="' + a + '"]').closest("li").removeClass("noMedia")
    }
    function l(a, b, c, d) {
        o("removeOwnMix", "click");
        var e = {
            playlistId: a,
            objectVersion: b,
            title: d,
            entityKey: c,
            onSuccess: function (a) {
                a.entityKey = c, comm.send("mix.deleted", a), o("removeOwnMix", "confirmed")
            },
            onCancel: function () {
                o("removeOwnMix", "cancelled")
            }
        };
        comm.send("mix.delete", e)
    }
    function m(c) {
        var d = b.find('[data-entity-key="' + c.playlist.entityKey + '"]').closest("li"),
            e = a(c.markup);
        d.replaceWith(e), Myspace.DragDrop.addDroppables(e)
    }
    function n(a) {
        b.find('[data-entity-key="' + a.entityKey + '"]').closest("li").remove()
    }
    function o(a, b) {
        comm.send("track", new Tracking("playerMixes", a, b))
    }
    var b = a("#mixes .list");
    comm.listen("mix.imageChanged", function (a) {
        i(a.playlistId, a.imgs)
    }, !0), comm.listen("mix.created", function (a) {
        h(a.markup)
    }, !0), comm.listen("mix.removeItem", function (a) {
        a.totalRecords || j(a.playlistId)
    }, !0), comm.listen("mix.addItem", function (a) {
        k(a.playlistId)
    }, !0), b.find(".newMix").click(function (a) {
        a.preventDefault(), a.stopPropagation(), comm.send("mix.create", {
            onSuccess: function () {
                o("newMix", "created")
            },
            onCancel: function () {
                o("newMix", "cancelled")
            }
        }), o("newMix", "click")
    }), b.click(function (b) {
        var c = a(b.target);
        if (c.hasClass("remove")) {
            b.preventDefault(), b.stopPropagation();
            var d = c.parent().children(".playBtn"),
                e = objectify(d),
                f = c.closest("li");
            f.hasClass("mix") ? l(e.playlistId, e.objectVersion, e.entityKey, e.title) : (comm.send("mix.deleted", e), comm.send("disconnect", {
                entityKey: e.entityKey,
                playlistId: e.playlistId,
                onSuccess: function (a) {
                    comm.send("connect.status", {
                        entityKey: e.entityKey
                    })
                }
            }), o("removeConnectedMix", "click"))
        } else if (!c.hasClass("playBtn") && !c.hasClass("artist")) {
            b.preventDefault(), b.stopPropagation();
            var g = c.closest("li").find(".title").attr("href");
            comm.send("location.href", g)
        } else c.hasClass("playBtn") && o("play")
    });
    var c = {
        $elem: b,
        activeClass: "dragee",
        ignoreSelectors: ".util",
        hoverSupressorClass: "transp",
        dragText: d,
        dragStart: e,
        dragEnd: f,
        drop: g
    };
    return new Myspace.SortManager(c), comm.listen("mix.deleted", n, !0), {
        add: h,
        edit: m,
        remove: n
    }
}(jQuery);
(function () {
    function l(a) {
        if (!j || a.mediaItem.mediaId != j.mediaId) j = a.mediaItem, k = !0;
        b.attr("data-panel") == "radio" && m()
    }
    function m() {
        if (!k) return;
        var a = "";
        j.radioStationEntityKey && (a += require("ejs").render(templates["common/views/footer/_queueItem"], {
            queueItem: {
                type: "radio",
                radioStationEntityKey: j.radioStationEntityKey,
                imageUrl: j.imageUrl,
                title: j.title,
                name: "Radio",
                disableLinks: !0
            }
        })), j.artistId ? $.post("/ajax/music/artist/" + j.artistId, null, function (b) {
            var c = b.artist || b.artists && b.artists[0],
                e;
            j.genreName && j.genreRadioStationEntityKey ? e = {
                genreId: j.genreId,
                name: j.genreName,
                radioStationEntityKey: j.genreRadioStationEntityKey
            } : c.genreName && c.genreRadioStationEntityKey && (e = {
                genreId: c.genreId,
                name: c.genreName,
                radioStationEntityKey: c.genreRadioStationEntityKey
            }), c && (a += require("ejs").render(templates["common/views/footer/_queueItem"], {
                queueItem: {
                    type: "radio",
                    radioStationEntityKey: c.radioStationEntityKey,
                    imageUrl: c.imageUrl,
                    title: c.name,
                    name: "Radio",
                    disableLinks: !0
                }
            })), e && (a += require("ejs").render(templates["common/views/footer/_queueItem"], {
                queueItem: {
                    type: "radio",
                    radioStationEntityKey: e.radioStationEntityKey,
                    imageUrl: config.urls.emptyAlbumImage,
                    title: e.name,
                    name: "Radio",
                    disableLinks: !0
                }
            })), d.find("li:not(.search)").remove(), d.append(a)
        }) : (j.genreName && j.genreRadioStationEntityKey && (a += require("ejs").render(templates["common/views/footer/_queueItem"], {
            queueItem: {
                type: "radio",
                radioStationEntityKey: j.genreRadioStationEntityKey,
                imageUrl: config.urls.emptyAlbumImage,
                title: j.genreName,
                name: "Radio",
                disableLinks: !0
            }
        })), d.find("li:not(.search)").remove(), d.append(a)), k = !1
    }
    function n(a, b) {
        comm.send("track", new Tracking("playerRadio", a, b))
    }
    var a = $("#footer"),
        b = $("#drawer"),
        c = $("#radio"),
        d = $(".options", c),
        e = $("#radioStations"),
        f = $("#radio .search"),
        g = $("#radioBtn"),
        h = $("#switcher"),
        i, j, k;
    comm.listen({
        player: {
            "+state": l,
            "+loading": l
        },
        drawer: {
            "+panel": function (a) {
                a == "radio" && m()
            }
        },
        radio: {
            "+started": function (b) {
                var c = e.find('.playBtn[data-radio-entity="' + b.radioEntity + '"]');
                if (c.length) c.parents("li").prependTo(e);
                else {
                    var b = require("ejs").render(templates["common/views/footer/_queueItem"], {
                        queueItem: b
                    });
                    e.prepend(b), a.removeClass("noStations")
                }
            }
        }
    }), g.on("hover", function () {
        m()
    }), h.on("hover", function () {
        m()
    }), d.on("click", function (a) {
        var b = $(a.target),
            c = b.closest("li");
        if (b.hasClass("playBtn")) {
            var d = b.attr("data-radio-station-entity-key"),
                e = d.indexOf("song") > -1 ? "song" : d.indexOf("artist") > -1 ? "artist" : d.indexOf("genre") > -1 ? "genre" : "";
            n("newStation", e);
            return
        }
        c.length && c.find(".playBtn").click()
    }), f.on("hover", function () {
        i || (i = new Myspace.RadioDialog)
    }).on("click", function () {
        i || (i = new Myspace.RadioDialog), i.$root.hasClass("open") || (i.show(), n("search", "clicked"))
    }), e.on("click", function (b) {
        var c = $(b.target),
            d = c.closest("li");
        if (c.hasClass("playBtn")) {
            n("existingStation"), setTimeout(function () {
                d.prependTo(e)
            }, 400);
            return
        }
        c.attr("data-action") == "remove" ? ($.post("/ajax/music/radio/remove", {
            radioEntity: d.find(".playBtn").attr("data-radio-entity")
        }), d.addClass("removing"), setTimeout(function () {
            d.remove(), e.find("li").length || a.addClass("noStations")
        }, 250)) : d.length && d.find(".playBtn").click()
    })
})();
Myspace.RadioSearch = function () {
    var a, b;
    return function (c, d) {
        a && a.abort();
        if (!c) {
            d();
            return
        }
        window.clearTimeout(b), b = window.setTimeout(function () {
            comm.send("track", new Tracking("radioSearchOverlay", "query")), a = $.ajax({
                type: "post",
                contentType: "application/json",
                url: "/ajax/search/autocomplete?" + $.param({
                    type: "song,artist",
                    limit: 10,
                    q: c,
                    includeGenres: !0
                }),
                success: d
            })
        }, 200)
    }
}(), Myspace.RadioDialog = function () {
    function d(c) {
        var d = c.keyCode == 8 ? c.target.value : c.target.value + String.fromCharCode(c.keyCode);
        d == "" ? b.removeClass("results") : Myspace.RadioSearch(d, function (c) {
            var d = "";
            c.songs && c.songs.forEach(function (a) {
                d += f({
                    radioStationEntityKey: a.radioStationEntityKey,
                    name: a.title,
                    imageUrl: a.imageUrl
                })
            }), c.artists && c.artists.forEach(function (a) {
                d += f({
                    radioStationEntityKey: a.radioStationEntityKey,
                    name: a.name,
                    imageUrl: a.imageUrl
                })
            }), c.genres && c.genres.forEach(function (a) {
                d += f({
                    radioStationEntityKey: a.radioStationEntityKey,
                    genreId: a.genreId,
                    name: a.name.replace("/", " / ").replace("  ", " "),
                    imageUrl: null
                })
            }), a.$root.find("ul.results").html(d), b.addClass("results")
        })
    }
    function e(a) {
        var b = "";
        return Array.isArray(a) && a.forEach(function (a) {
            b += f({
                radioStationEntityKey: a.radioStationEntityKey,
                genreId: a.genreId,
                name: a.name.replace("/", " / ").replace("  ", " "),
                imageUrl: null
            })
        }), b
    }
    function f(a) {
        return "<li>" + play("radio", a) + '<img src="' + (a.imageUrl || config.urls.emptyAlbumImage) + '"><div><span>' + a.name + "</span></div></li>"
    }
    function g(a, b) {
        comm.send("track", new Tracking("radioSeachOverlay", a, b))
    }
    var a = new Myspace.Dialog($(require("ejs").render(templates["areas/music/views/radioDialog"])).appendTo("body")),
        b = a.$root.find(".search"),
        c;
    $.post("/ajax/music/genres/featured", null, function (b) {
        var c = e(b);
        a.$root.find("ul.genres").html(c), a.$root.hasClass("open") && a.center()
    }), a.$root.on("click", function (b) {
        var c = $(b.target);
        if (c.hasClass("playBtn")) {
            a.hide(), c.closest("ul.results", a.$root).length ? g("click", "results") : c.closest("ul.genres", a.$root).length && g("click", "genres");
            return
        }
        var d = c.closest("li").find(".playBtn.radio");
        return d.length && d.click(), c.is("a")
    }).on("submit", function () {
        return !1
    }), a.$root.find("input").on("keypress", d).on("keyup", function (a) {
        a.keyCode == 8 && d(a)
    }), this.hide = a.hide, this.$root = a.$root, this.show = function () {
        function b() {
            context.beaconData.pf = c, comm.stopListening("dialog.hide", b)
        }
        a.show(), g("invoke"), c = context.beaconData.pf, context.beaconData.pf = "radiosearchoverlay", comm.send("beacon", context.beaconData), comm.listen("dialog.hiding", b)
    }
};
(function () {
    function v(a) {
        var b = a / 60 | 0,
            c = "0" + Math.floor(a % 60);
        return b + ":" + c.substr(c.length - 2)
    }
    function C(a) {
        A || B.percent(a), z.width(a * 100 + "%"), x.attr("class", "noStyle volume_" + (a < .05 ? "off" : a >= .05 && a < .2 ? "low" : a >= .2 & a < .8 ? "mid" : "max"))
    }
    function D(b) {
        a = b.mediaItem;
        if (e.hasClass("ad")) return;
        F(b.mediaItem), M(b.mode), E(b.paused), o.html(v(b.time) + " /"), p.html(v(a.duration)), s.width(b.time / a.duration * 100 + "%"), u.percent(b.time / a.duration)
    }
    function E(a) {
        e.toggleClass("paused", a), Q("play", a ? "Play" : "Pause")
    }
    function F(a) {
        G(a.title, a.titleVersion, a.isExplicit, a.url || a.detailUrl), H(a.artistName, a.artistUrl), I(a.title, a.artistName), L(a.sourceName || a.albumTitle, a.sourceUrl || a.albumUrl), O(a.video)
    }
    function G(a, b, c, d, e, f) {
        var g = "";
        a && (d ? (g = $("<a></a>").attr("href", d).text(a).click(f), e && g.attr("target", e)) : g = $("<span></span>").text(a)), b && g.append('\n<span class="version">(' + b + ")</span>"), c && g.append('\n<i class="explicit_10"></i>'), k.html(g)
    }
    function H(a, b) {
        var c = "";
        a && (c = (b ? $("<a></a>").attr("href", b) : $("<span></span>")).text(a)), l.html(c)
    }
    function I(a, b) {
        var c = "";
        a && (c = $("<b></b>").text(a)), b && c.append(" by " + b), document.title = c.text() || "Myspace"
    }
    function L(a, b) {
        j.attr("class", "track");
        var c = "";
        a && (c = (b ? $("<a></a>").attr("href", b).attr("title", a) : $("<span></span>")).text(a)), J && clearTimeout(J), K && clearInterval(K), setTimeout(function () {
            n.html(c)
        }, 1e3), c && (J = setTimeout(function () {
            j.attr("class", "source")
        }, 1e4), K = setInterval(function () {
            j.attr("class", "track"), J = setTimeout(function () {
                j.attr("class", "source")
            }, 1e4)
        }, 13e3))
    }
    function M(a) {
        var b = $("#playControls .connectButton"),
            c = $("#queue .list." + a + " .selected .connectButton");
        if (c.length) {
            var d = $('<button data-action="connect"><span></span><span></span></button>');
            $.each(c.prop("attributes"), function (a, b) {
                b.name != "data-popover-initialized" && d.attr(b.name, b.value)
            }), d.addClass("dark"), b.replaceWith(d), comm.send("hcard.init", f)
        } else b.attr("disabled", "disabled")
    }
    function N(a) {
        H(a ? "(skip in " + Math.ceil(a) + " seconds)" : ""), a === 0 && g.removeAttr("disabled")
    }
    function O(a) {
        var b = "";
        a && a.mediaType == "video" && (b = $('<a href="' + a.detailUrl + '"><i class="video_16" target="_self"></i></a>').click(function () {
            return comm.send("queue.find.video", a), Myspace.VideoPlayer.closed = !1, Myspace.VideoPlayer.show(), !1
        })), m.html(b)
    }
    function P() {
        var a = $("#playControls button, #modeControls button"),
            b = $();
        e.hasClass("empty") && (b = a.not('[data-action="radio"]')), e.hasClass("radio") && (b = a.filter('[data-action="shuffle"], [data-action="repeat"], [data-action="previous"]')), e.hasClass("preview") && (b = a.filter('[data-action="shuffle"], [data-action="repeat"], [data-action="radio"]')), e.hasClass("ad") && (b = a.filter('[data-action="previous"], [data-action="next"], [data-action="connect"], [data-action="shuffle"], [data-action="repeat"]')), a.not(b).removeAttr("disabled"), b.attr("disabled", "disabled");
        var c = "";
        b.each(function (a, b) {
            var d = b.getAttribute("data-tip-name");
            d && (c += (c.length ? ", " : "") + '.footertip[data-name="' + d + '"]')
        }), $(c).hide()
    }
    function Q(a, b) {
        var c = $("body");
        c.find('.tip[data-name="' + a + '"] .tip-inner').text(b), c.find('[data-tip-name="' + a + '"]').attr("data-original-title", b)
    }
    function R(a, b, c) {
        comm.send("track", new Tracking(a, b, c))
    }
    var a, b, c, d = $("body"),
        e = $("#footer"),
        f = $("#player"),
        g = $('#playControls button[data-action="next"]'),
        h = $("#incognito");
    f.on("click", function (a) {
        var b = $(a.target).closest("[data-action]:not([disabled])"),
            c = b.attr("data-action");
        if (c) switch (c) {
                case "radio":
                    var d = e.hasClass("radio");
                    d ? (comm.send("queue.activate"), R("player", "radio", "off")) : R("player", "radio", "clicked"), comm.send("drawer.panel", d ? "queue" : "radio");
                    break;
                case "mixes":
                case "queue":
                    return comm.send("drawer.panel", c), R("player", "panel", c), !1;
                case "play":
                    c = e.hasClass("paused") ? "resume" : "pause", comm.send("player." + c), R("player", c);
                    break;
                case "connect":
                    R("player", "connect", b.hasClass("connected") ? "disconnect" : "connect");
                    break;
                case "shuffle":
                    comm.send("player.shuffle"), R("player", "shuffle", e.hasClass("shuffled") ? "on" : "off");
                    break;
                case "repeat":
                    comm.send("player.repeat"), R("player", "repeat", e.hasClass("repeatAll") ? "all" : e.hasClass("repeatOne") ? "one" : "off");
                    break;
                case "mute":
                    comm.send("player.mute"), R("player", "mute", e.hasClass("muted") ? "on" : "off");
                    break;
                case "signin":
                    return comm.send("login.show", {
                        signupContext: {
                            promptAction: "signInPlayer"
                        }
                    }), !1;
                default:
                    R("player", c), comm.send("player." + c)
        }
    });
    var i = $("#nowPlaying"),
        j = $("h5", i),
        k = $(".title", i),
        l = $(".artist", i),
        m = $(".videoLink", i),
        n = $(".source span", i),
        o = $(".time", i),
        p = $(".duration", i),
        q = $(".meter", i),
        r = $(".buffer", q),
        s = $(".trailer", q),
        t, u = new Myspace.Slider(q, {
            units: "%",
            axis: "x",
            jump: function (b, c) {
                o.html(v(b / c * a.duration) + " /"), s.width(b / c * 100 + "%"), comm.send("player.seek", b / c * a.duration), R("player", "seek")
            },
            drag: function (a, b) {
                t = !0, s.width(a / b * 100 + "%")
            },
            stop: function (b, c) {
                t = !1, comm.send("player.seek", b / c * a.duration), R("player", "seek")
            }
        }),
        w = $("#volumeControl"),
        x = $("#volumeBtn"),
        y = $(".meter", w),
        z = $(".trailer", w),
        A, B = new Myspace.Slider(y, {
            units: "%",
            axis: "x",
            jump: function (a, b) {
                comm.send("player.volume", a / b), R("player", "volume")
            },
            drag: function (a, b) {
                A = !0, comm.send("player.volume", a / b)
            },
            stop: function (a, b) {
                A = !1, R("player", "volume")
            }
        });
    comm.listen({
        player: {
            "+mode": function (a) {
                e.removeClass("radio queue preview").addClass(a).toggleClass("empty", !$("#queue .list." + a + " li").length), P()
            },
            "+preloading": function (a) {
                e.hasClass("ad") ? (c = Myspace.genericDialog({
                    html: "<p>Your " + a.mediaItem.type + " has been queued. It will begin shortly.</p>",
                    id: "queuedDialog",
                    buttons: null,
                    close: !1
                }), setTimeout(function () {
                    c.hide()
                }, 3e3)) : (r.width("0%"), D(a))
            },
            "+loading": function (a) {
                b = !0, e.removeClass("ad"), r.width("0%"), D(a)
            },
            "+loaded": function (a) {
                b = !1
            },
            "+paused": function () {
                E(!0)
            },
            "+resumed": function () {
                E(!1)
            },
            "+ended": function () {
                E(!0)
            },
            "+state": function (a) {
                D(a), E(a.paused)
            },
            "+time": function (c) {
                b || (o.html(v(c.time) + " /"), t || (s.width(Math.min(c.time / a.duration, 1) * 100 + "%"), u.percent(Math.min(c.time / a.duration, 1))), r.width(Math.min((c.time + c.buffer) / a.duration, 1) * 100 + "%"))
            },
            "+duration": function (a) {
                p.html(v(a)).attr("data-duration", a)
            },
            "+volumeChanged": function (a) {
                C(a), e.removeClass("muted")
            },
            "+muted": function () {
                C(0), Q("mute", "Unmute"), e.addClass("muted")
            },
            "+unmuted": function () {
                C(Cookies.player.values.volume), Q("mute", "Mute"), e.removeClass("muted")
            },
            "+repeatChanged": function (a) {
                e.toggleClass("repeatAll", a == "all").toggleClass("repeatOne", a == "one")
            },
            "+shuffleChanged": function (a) {
                e.toggleClass("shuffled", a)
            },
            "+queueChanged": function (a) {
                e.hasClass(a) && e.toggleClass("empty", !$("#queue .list." + a + " li").length), P()
            },
            "+adStarted": function (a) {
                var b = a.clickThroughUrl.indexOf(document.domain) == -1 && a.clickThroughUrl.indexOf("new.myspace.com") == -1,
                    c = b ? "_blank" : "",
                    d = a.adInfo && a.adInfo != "",
                    f = b || !d ? "Advertisement Info" : a.adInfo;
                G(f, undefined, undefined, a.clickThroughUrl, c, function () {
                    comm.send("player.adClicked", {
                        isAd: !0,
                        type: a.isVideo ? "video" : "song"
                    }), b && a.isVideo && comm.send("player.pause")
                }), N(a.enableSkipAfter), L(), s.width(0), r.width(0), q.attr("disabled", "disabled"), e.addClass("ad"), P()
            },
            "+adDuration": function (a) {
                p.html(v(a)).attr("data-duration", a)
            },
            "+adRemainingTime": function (a) {
                if (e.hasClass("ad")) {
                    o.html(v(a.remainingTime) + " /"), r.width(0);
                    var b = parseInt(p.attr("data-duration"));
                    s.width((b - a.remainingTime) / b * 100 + "%"), N(a.enableSkipAfter)
                }
            },
            "+adStopped": function () {
                c && c.hide(), q.removeAttr("disabled"), P(), e.removeClass("ad")
            },
            "+videoPreview": function (a) {
                O(a)
            },
            "+incognitoChanged": function (a) {
                h.toggleClass("on", a)
            }
        }
    });
    var J, K;
    P()
})();
(function () {
    var a = {
        FBAuth: null,
        FBUserId: null,
        url: window.location.href,
        FBSongUrl: window.location.href.indexOf("/queue") >= 0 ? queryString.song : "",
        prevActionId: 0,
        getId: function (a) {
            return a.substr(a.lastIndexOf("-") + 1)
        },
        play: function (b) {
            window.console && console.log("play called from FB"), window.console && console.log(b);
            var c = a;
            if (b.song) c.FBSongUrl = b.song, comm.send("queue.play.song", c.getId(b.song));
            else if (b.album) comm.send("queue.set.album", {
                    albumId: c.getId(b.album)
                });
            else if (b.playlist) {
                var d = c.getId(b.playlist),
                    e = b.playlist.replace("//", "").split("/");
                comm.send("queue.set.mixtape", {
                    playlistId: d,
                    profileId: e[1]
                })
            } else if (b.musician) comm.send("radio.artist", c.getId(b.musician.toLowerCase().replace("/songs", "")));
            else if (b.radio_station) {
                var f = b.radio_station.toLowerCase().replace("/radio", "");
                f = f.substr(f.lastIndexOf("/") + 1), comm.send("radio.genre", f)
            }
        },
        pause: function (a) {
            window.console && console.log("pause called from FB"), comm.send("player.pause", {})
        },
        resume: function (a) {
            comm.send("player.play")
        },
        sendStatus: function (b) {
            var c = a;
            if (b && typeof b == "number") {
                c.FBAuth && c.FBSongUrl && (window.console && console.log("Facebook Status: Error, ErrorCode: " + b + " ,song: " + c.FBSongUrl), FB.Music.send("STATUS", {
                    error_code: b,
                    playing: !1,
                    song: c.FBSongUrl,
                    user_id: c.FBAuth.authResponse.userID
                })), c.FBSongUrl = "";
                return
            }
            comm.send("player.nowPlaying", function (b) {
                var d = b.mediaItem;
                c.prevMediaId && c.prevMediaId != d.mediaId && c.prevActionId && c.prevStartTime > (new Date).getTime() - 15e3 && $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "/ajax/music/deleteaction",
                    data: {
                        actionId: c.prevActionId
                    },
                    success: function (a) {}
                });
                var e = localStorage.getItem("incognito");
                if ((e == null || e == "0") && c.prevMediaId != d.mediaId && (d.mediaType != "audio" || d.streamUrl)) {
                    d.mediaType == "video" ? $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/ajax/video/sendwatch",
                        data: {
                            videoId: d.mediaId,
                            fbUserId: c.FBUserId
                        },
                        success: function (b) {
                            if (b.success) try {
                                    b = $.parseJSON(b.response);
                                    var c = a;
                                    c.prevMediaId = d.mediaId, c.prevStartTime = (new Date).getTime(), c.prevActionId = b.id
                            } catch (e) {
                                b = null
                            }
                        }
                    }) : $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/ajax/music/sendlisten",
                        data: {
                            songId: d.mediaId,
                            fbUserId: c.FBUserId
                        },
                        success: function (b) {
                            if (b.success) try {
                                    b = $.parseJSON(b.response);
                                    var c = a;
                                    c.prevMediaId = d.mediaId, c.prevStartTime = (new Date).getTime(), c.prevActionId = b.id
                            } catch (e) {
                                b = null
                            }
                        }
                    }), e != null && e != "0" && (a.prevActionId = 0);
                    if (d.mediaType == "audio" && c.FBAuth) {
                        if (!(!c.FBSongUrl || c.getId(c.FBSongUrl) == d.mediaId && d.state === "playing")) {
                            c.sendStatus(103);
                            return
                        }
                        var f = (new Date).getTime() - d.time * 1e3 + (new Date).getTimezoneOffset() * 6e4;
                        f = new Date(f);
                        var g = f.getFullYear() + "-" + (f.getMonth() + 1) + "-" + f.getDate() + "T" + f.getHours() + ":" + f.getMinutes() + ":" + f.getSeconds();
                        window.console && console.log("Status: " + d.state + " name: " + d.songTitle + "start: " + g + " duration: " + d.duration), FB.Music.send("STATUS", {
                            playing: d.state === "playing",
                            song: "http://www.myspace.com" + d.songURL,
                            start_time: g,
                            expires_in: d.duration,
                            user_id: c.FBAuth.authResponse.userID
                        })
                    }
                }
            })
        },
        renewToken: function () {
            $("body").append('<iframe id="fbAuth" sandbox="allow-forms allow-same-origin allow-scripts" src="/thirdpartyauth/facebook/renewToken"></iframe>')
        },
        loginStatusCallback: function (b) {
            $("style:contains(fb_)").addClass("spaceway");
            var c = a;
            if (b.status == "connected") {
                c.response = b, FB.api("/me/permissions", function (a) {
                    a.data[0].publish_actions && !c.FBUserId && (c.FBUserId = b.authResponse.userID)
                });
                var d = (new Date).getMonth() * 100 + (new Date).getDate();
                if (!localStorage.FBLastRenewed || localStorage.FBLastRenewed != d) {
                    c.renewToken();
                    try {
                        localStorage.FBLastRenewed = d
                    } catch (e) {}
                }
            }
        },
        processQueryStrings: function () {
            if (queryString.song || queryString.albom || queryString.playlist || queryString.musician) this.play(queryString), history.replaceState("", null, window.location.pathname)
        },
        fbAsyncInit: function () {
            var b = a;
            FB.init({
                appId: config.thirdParty.facebookAppId,
                status: !0,
                cookie: !0,
                xfbml: !0,
                music: !0,
                oauth: !0,
                frictionlessRequests: !0
            }), FB.getLoginStatus(b.loginStatusCallback, !0), b.processQueryStrings()
        },
        FBConnected: function (b) {
            var c = a;
            c.FBAuth = b, b && (FB.Event.subscribe("fb.music.PLAY", c.play), FB.Event.subscribe("fb.music.RESUME", c.resume), FB.Event.subscribe("fb.music.PAUSE", c.pause), FB.Event.subscribe("fb.music.STATUS", c.sendStatus)), comm.listen({
                queue: {
                    "+playing": function (a) {
                        if (typeof a.media == "undefined" || !a.media) return;
                        c.FBSongUrl && c.FBSongUrl.lastIndexOf(a.media.songId) < 0 && (c.FBSongUrl = ""), c.sendStatus()
                    },
                    "+paused": function (a) {
                        c.sendStatus()
                    },
                    "+end": function (a) {
                        c.sendStatus()
                    },
                    "+error": function (b) {
                        var c = a;
                        b && b.type && (b.type === "flash" && b.msg.startsWith("stream rejected") ? c.sendStatus(4) : b.type === "permissions" && c.sendStatus(103))
                    }
                }
            }), a.sendStatus()
        },
        init: function () {
            window.fbAsyncInit = this.fbAsyncInit, $("body").append('<div id="fb-root"></div>');
            var a = document.createElement("script");
            a.async = !0, a.src = document.location.protocol + "//connect.facebook.net/en_US/all/vb.js", document.getElementsByTagName("head")[0].appendChild(a)
        }
    };
    a.init()
})();
(function () {
    function j(b) {
        if (!Myspace.Player.active) return;
        var d = i("mode"),
            e = i("shuffled"),
            j = {
                actionText: b,
                albumId: a.albumId || null,
                artistId: a.artistId,
                catalogReportedMediaTotalLengthSeconds: a.duration,
                currentPlayheadPositionSeconds: f,
                deltaPlayElapsedSeconds: g - h,
                drawerPinnedIndicator: i("pinned"),
                drawerVisibleIndicator: $("body").hasClass("queueOpen"),
                influencerId: a.influencerId || null,
                firstAutoPlayIndicator: c == 1,
                majorModeText: d,
                mediaId: a.mediaId,
                mediaReleaseId: a.mediaReleaseId,
                mediaTypeText: a.mediaType == "audio" ? "song" : a.mediaType,
                minorModeText: c == 1 ? "firstPlay" : "",
                muteEnabledIndicator: i("mute"),
                originalStreamStartUtcDateTime: a.streamStartDateTime,
                pausedIndicator: i("paused"),
                playerBundleVersionValue: 1,
                playerBufferState: null,
                queueSourceEntityKeyText: a.sourceEntityKey == "" ? null : a.sourceEntityKey,
                radioStationEntityKeyText: d == "radio" ? i("radioEntity") : null,
                repeatModeText: i("repeat"),
                sampleIndicator: !a.isFullLength,
                shuffleEnabledIndicator: e,
                totalPlayElapsedSeconds: g,
                volumeLevelValue: i("volume")
            };
        h = g, comm.send("beacon.v2", j)
    }
    var a, b = !1,
        c = 0,
        d = 10,
        e = 1,
        f = 0,
        g = 0,
        h = 0,
        i = new CookieHelper("player");
    comm.listen({
        player: {
            "+loading": function (d) {
                a = d.mediaItem, f = d.time, g = 0, h = 0, e = 1, b = !1, d.mode == "queue" && c++, j("AttemptLoadStream")
            },
            "+paused": function () {
                j("Pause")
            },
            "+time": function (a) {
                f = a.time, g = a.tsl, b ? g > d * e && (j("PlayedInterval"), e++) : (j("PlayStarted"), b = !0)
            }
        }
    })
})();
var UnityMusicShim = function () {
    var a = {};
    return a.sendState = function (a) {
        var b = document.createEvent("CustomEvent");
        b.initEvent("UnityStateEvent", !0, !0), document.body.setAttribute("data-unity-state", JSON.stringify(a)), document.body.dispatchEvent(b, a)
    }, document.body.addEventListener("UnityActionEvent", function (b) {
        var c = JSON.parse(document.body.getAttribute("data-unity-action"));
        a._callbackObject && a._callbackObject[c]()
    }), a.setCallbackObject = function (b) {
        a._callbackObject = b
    }, a.setSupports = function (a) {
        var b = document.createEvent("CustomEvent");
        b.initEvent("UnitySupportsEvent", !0, !0), document.body.setAttribute("data-unity-supports", JSON.stringify(a)), document.body.dispatchEvent(b, a)
    }, a
};
(function () {
    function c(c, d) {
        if (!c) return a.sendState({});
        b = c.mediaItem, a.sendState({
            playing: !c.paused,
            title: b.title,
            artist: b.artistName,
            favorite: objectify($("#player .connectButton")).isConnected,
            albumArt: b.imageUrl
        })
    }
    var a = UnityMusicShim(),
        b;
    a.setSupports({
        playpause: !0,
        next: !0,
        previous: !0,
        favorite: !0
    }), a.setCallbackObject({
        pause: function () {
            comm.send("player.playPause")
        },
        next: function () {
            comm.send("player.next")
        },
        previous: function () {
            comm.send("player.previous")
        },
        favorite: function () {
            $("#player .connectButton").click()
        }
    }), comm.listen("connect.status", function (a) {
        if (a.entityKey != b.entityKey) return;
        c({
            mediaItem: b,
            paused: !1
        }, "player.connect")
    }, !0), comm.listen({
        player: {
            "+state": c,
            "+loaded": c,
            "+loading": c,
            "+listChanged": function (a) {
                a.list.length == 0 && c()
            }
        }
    })
})();
(function () {
    function a(a) {
        Cookies.player.refresh(), localStorage["ps_" + a] = JSON.stringify(Cookies.player.parsedValues)
    }
    function b(a) {
        var b = localStorage["ps_" + a];
        Cookies.player.values = b ? JSON.parse(b) : {}, Cookies.save(Cookies.player, "." + document.domain, (new Date).addDays(30))
    }
    comm.listen("signout", function () {
        a(context.profileId), b(-1)
    }, !0), comm.listen("signin", function (c) {
        a(-1), b(c.profileId)
    }, !0), localStorage.incognito != undefined && (comm.send("player.incognito", localStorage.incognito == 1), delete localStorage.incognito)
})();